<?php

$redis = new Redis();
$redis->connect('127.0.0.1', '6379', 5);
$redis->auth('123456');

if (isset($_SERVER["HTTP_X_REQUESTED_WITH"])) {
    $page = $_GET['page'] ?? 1;
    $limit = $_GET['limit'] ?? 10;
    $begin = ($page - 1) * $limit;
    $end = $begin + $limit - 1;
    $images = $redis->hGetAll('img_list');
    $num = 0;
    $data = $temp = [];
    foreach ($images as $k => $v) {
        if ($num < $begin || $num > $end) {
            $num++;
            continue;
        }
        $v = json_decode($v, true);
        $temp['id'] = $k;
        $temp['savePath'] = $v['savePath'];
        $temp['thumb_image'] = $v['thumb_image'];
        $temp['name'] = $v['name'];
        $data[] = $temp;
        $num++;
    }
    layuiReturn($data, count($images));
}

include_once "html/admin.php";


function layuiReturn($param, $count)
{
    $data['code'] = 0;
    $data['msg'] = '';
    $data['count'] = $count;
    $data['data'] = $param;

    echo json_encode($data);
    exit();
}
